set(QNX TRUE)
set(CMAKE_SYSTEM_NAME QNX)

set(QNX_HOST "$ENV{QNX_HOST}")
set(QNX_TARGET "$ENV{QNX_TARGET}")
if(NOT QNX_HOST)
  message(FATAL_ERROR "Environment variable QNX_HOST not set!")
endif()
if(NOT QNX_TARGET)
  message(FATAL_ERROR "Environment variable QNX_TARGET not set!")
endif()

if(ARM_TARGET_ARCH_ABI STREQUAL "armv8")
  set(QNX_PROCESSOR aarch64)
  set(QNX_COMPILER_TARGET gcc_ntoaarch64le_cxx)
  set(QNX_NTO_ARCH aarch64)
elseif(ARM_TARGET_ARCH_ABI STREQUAL "armv7")
  set(QNX_PROCESSOR armle-v7)
  set(QNX_COMPILER_TARGET gcc_ntoarmv7le_cxx)
  set(QNX_NTO_ARCH armv7)
else()
  message(FATAL_ERROR "QNX only supports ARM_TARGET_ARCH_ABI=armv8 or armv7!")
endif()

set(CMAKE_C_COMPILER ${QNX_HOST}/usr/bin/qcc)
set(CMAKE_C_COMPILER_TARGET ${QNX_COMPILER_TARGET})
set(CMAKE_CXX_COMPILER ${QNX_HOST}/usr/bin/q++)
set(CMAKE_CXX_COMPILER_TARGET ${QNX_COMPILER_TARGET})
# Don't use CMAKE_ASM_COMPILER_TARGET before version 3.14, refer to https://gitlab.kitware.com/cmake/cmake/-/merge_requests/3016
set(CMAKE_ASM_COMPILER ${QNX_HOST}/usr/bin/qcc -V${QNX_COMPILER_TARGET})
set(CMAKE_ASM_DEFINE_FLAG "-Wa,--defsym,")
set(CMAKE_STRIP ${QNX_HOST}/usr/bin/nto${QNX_NTO_ARCH}-strip CACHE PATH "QNX strip program" FORCE)
